package com.ruoyi.project.rate.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ruoyi.framework.web.service.CrudService;
import com.ruoyi.project.rate.domain.Result;
import com.ruoyi.project.rate.mapper.ResultMapper;

@Service
public class ResultService extends CrudService<ResultMapper, Result> {
	@Autowired
	private ResultMapper resultMapper;
	
	@Transactional(readOnly = false)
	public void batchSave(List<Result> resultList) {
		for (Result result : resultList) {
			this.save(result);
		}
	}
	
	@Override
	@Transactional(readOnly = false)
	public int save(Result result) {
		// 先删除、后插入
		this.deleteByMonthIdAndDept(result);
		return super.save(result);
	}
	
	@Transactional(readOnly = false)
	public int deleteByMonthIdAndDept(Result result) {
		return this.resultMapper.deleteByMonthIdAndDept(result);
	}
	
	@Transactional(readOnly = false)
	public void batchUpdateRank(List<Result> resultList) {
		for (Result result : resultList) {
			this.resultMapper.updateRank(result);
		}
	}
}
